package com.casic.common.utils;

import org.apache.commons.lang.StringUtils;

import java.util.List;

public class CommonUtil {

	public static String replaceUnderlineAndfirstToUpper(String srcStr,
			String org, String ob) {
		String newString = "";
		int first = 0;
		while (srcStr.indexOf(org) != -1) {
			first = srcStr.indexOf(org);
			if (first != srcStr.length()) {
				newString = newString + srcStr.substring(0, first) + ob;
				srcStr = srcStr
						.substring(first + org.length(), srcStr.length());
				if(!StringUtils.isBlank(srcStr)){
					srcStr = firstCharacterToUpper(srcStr);
				}
				
			}
		}
		newString = newString + srcStr;
		return newString;
	}

	public static String firstCharacterToUpper(String srcStr) {
		return srcStr.substring(0, 1).toUpperCase() + srcStr.substring(1);
	}
	
	public static String getFieldName(String keyName, String splitStr, String replaceStr) {
		if(isAllUpperCase(keyName)){
			keyName = keyName.toLowerCase();
		}
		return replaceUnderlineAndfirstToUpper(keyName, "_", "");
	}
	
	public static boolean isAllUpperCase(String word){
		for(int i = 0; i < word.length(); i++) {
			char c = word.charAt(i);
			if ((c <= 'Z' && c >= 'A')
					|| (c <= 'z' && c >= 'a')) {
				if (Character.isLowerCase(c)) {
					return false;
				}
			}
		}
		return true;
	 }

	/**
	 * 根据 roleId 集合检查是否为公安人员
	 * @param roleIds roleId 集合
	 * @return 是否为公安人员
	 */
	public static boolean isGongan(List<String> roleIds) {
		if(roleIds.size() != 1) {
			return false;
		}
		boolean result = false;
		for(String roleId : roleIds) {
			if(Constant.POLICE_ROLE_ID.equals(roleId)) {
				result = true;
			}
		}
		return result;
	}

	/**
	 * 根据 roleId 集合检查是否为典当企业管理员角色
	 * @param roleIds roleId 集合
	 * @return 是否为典当企业管理员角色
	 */
	public static boolean isDdqy(List<String> roleIds) {
		if(roleIds.size() != 1) {
			return false;
		}

		boolean result = false;
		for(String roleId : roleIds) {
			if(Constant.DDQY_ROLE_ID.equals(roleId)) {
				result = true;
			}
		}
		return result;
	}
}
